package com.xsm.activitygroup;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.message.BasicNameValuePair;
import com.umeng.analytics.MobclickAgent;
import com.xsm.activitygroup.R;
import com.xsm.internet.PostMessage;
import com.xsm.view.LoadDialog;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
public class FeedBack extends Activity{
	com.xsm.view.ClearEditText contentEditText;
	LinearLayout layout;
	Myhandler hanMyhandler;
	Context context;
	LoadDialog dialog;
	
protected void onCreate(Bundle savedInstanceState) {
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	super.onCreate(savedInstanceState);
	setContentView(R.layout.feedback);
	hanMyhandler=new Myhandler();
	context=this;
	dialog=new LoadDialog(context,"正在提交...");
	contentEditText=(com.xsm.view.ClearEditText)findViewById(R.id.content);
	layout=(LinearLayout)findViewById(R.id.issuelayout);
	layout.setOnClickListener(new OnClickListener() {
		public void onClick(View arg0) {
		contentEditText.requestFocus();
		InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
		}
	});
	
	Button button=(Button)findViewById(R.id.issue);button.getBackground().setAlpha(180);
			
}
public void Back(View view){
	finish();
}
public void Issue(View view){
	SharedPreferences sharedPreferences=getSharedPreferences("XSM", 0);
	final String userid=sharedPreferences.getString("User", "");
	if(userid.equals("")){
		Toast.makeText(context,"请先登陆",Toast.LENGTH_LONG).show();
	}else {
		dialog.showDialog();
		new Thread(new Runnable() {
			public void run() {
				List params=new ArrayList();
				params.add(new BasicNameValuePair("ASK","IssueQuanzi"));
				params.add(new BasicNameValuePair("userid",userid));	
				params.add(new BasicNameValuePair("content",contentEditText.getText().toString().trim()));
				PostMessage postMessage=new PostMessage(params);
				String result=postMessage.getResult();
				Message msg=hanMyhandler.obtainMessage();
				if(result.equals("1")){
					msg.what=1;
				}else {
					msg.what=2;
				}
				hanMyhandler.sendMessage(msg);
			}
		}).start();	
	}
}

class Myhandler  extends Handler{
	public void handleMessage(Message msg) {
		dialog.dissmissDialog();
		if(msg.what==1){
			Toast.makeText(context, "发布成功,感谢您的反馈", Toast.LENGTH_LONG).show();
			finish();
		}
		else
		Toast.makeText(context, "发布失败,请检查网络配置", Toast.LENGTH_LONG).show();
	
		super.handleMessage(msg);
	}
}

@Override
protected void onResume() {
	MobclickAgent.onResume(this);
	super.onResume();
}
@Override
protected void onPause() {
	MobclickAgent.onResume(this);
	super.onPause();
}
}
